import Vue from 'vue'
import Vuex from 'vuex'
import {
	logout
} from '../api/index.js'

Vue.use(Vuex)

const store = new Vuex.Store({
	state: {
		hasLogin: wx.getStorageSync('userInfo') ? true : false,
		userInfo: {},
		tabbarValue: '/pages/index/index'
	},
	mutations: {
		settabbarValue(state, data) {
			state.tabbarValue = data
		},
		login(state, provider) {
			state.hasLogin = true;
			state.userInfo = provider;
			uni.setStorage({ //缓存用户登陆状态
				key: 'userInfo',
				data: provider
			})
		},
		async logout(state) {
			let res = await logout()
			if (res.code == 200) {
				state.hasLogin = false;
				state.userInfo = {};
				uni.removeStorage({
					key: 'userInfo'
				})
			}

		}
	},
	actions: {

	}
})

export default store